//
//  AllBrandsTableViewCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/10/10.
//

import UIKit

class AllBrandsTableViewCell: UITableViewCell {
    var selectBtn: UIButton!
    var carImageView: UIImageView!
    var brandNameLab: UILabel!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.backgroundColor = Theme.F5Color
        self.selectionStyle = .none
        self.clipsToBounds = true
        
        self.selectBtn = UIButton(frame: CGRect(x: 10, y: 4, width: 105, height: 44))
        self.selectBtn.setImage(UIImage(named: "icon_brand_normal"), for: .normal)
        self.selectBtn.setImage(UIImage(named: "icon_brand_select"), for: .selected)
        self.selectBtn.isUserInteractionEnabled = false
        self.contentView.addSubview(self.selectBtn)
        
        self.carImageView = UIImageView(frame: .zero)
        self.carImageView.backgroundColor = .white
        self.contentView.addSubview(self.carImageView)
        
        self.brandNameLab = UILabel(frame: CGRect.zero)
        self.brandNameLab.textColor = Theme.mainColor
        self.brandNameLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        self.brandNameLab.numberOfLines = 2
        self.brandNameLab.textAlignment = .left
        self.contentView.addSubview(self.brandNameLab)
        self.brandNameLab.text = "阿斯顿马丁"
        self.addLayout()
        
     
    }
    
    
    func addLayout(){
        self.selectBtn.snp.makeConstraints { make in
            make.top.equalTo(12)
            make.left.equalTo(14)
            make.height.width.equalTo(16)
            make.centerY.equalTo(self.snp.centerY)
        }
        
        self.carImageView.snp.makeConstraints { make in
            make.top.equalTo(7)
            make.left.equalTo(self.selectBtn.snp.right).offset(10)
            make.height.width.equalTo(30)
        }
        self.carImageView.layer.cornerRadius = 15
        self.carImageView.clipsToBounds = true
        
        self.brandNameLab.snp.makeConstraints { make in
            make.top.equalTo(4)
            make.left.equalTo(self.carImageView.snp.right).offset(10)
            make.right.equalTo(-50)
            make.centerY.equalTo(self.selectBtn.snp.centerY)
        }
    }
    
    
    
    
    //setModel
    func setContentModel(model: BrandSeriesListModel){
        if let url = URL.init(string: model.brandLog ?? "") {
            self.carImageView.sd_setImage(with: url)
            self.carImageView.isHidden = false
            self.carImageView.snp.updateConstraints { make in
                make.height.width.equalTo(30)
            }
        }else{
            self.carImageView.isHidden = true
            self.carImageView.snp.updateConstraints { make in
                make.width.equalTo(0)
                make.height.equalTo(0)
            }
        }
        self.brandNameLab.text = model.brandName ?? ""
        self.selectBtn.isSelected = model.isSelect
        self.updateConstraints()
    }

    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
